// wgldebug.cpp
//

#include "config.h"
#include "wgl/wgldebug.hpp"

using namespace wgl;

#ifdef HAVE_BOOST
#  include <boost/core/demangle.hpp>
#endif



std::unordered_map<void *, std::string> object_names{};
  


// wgl::wgl_type_name
//
std::string wgl::wgl_type_name ( const std::type_info &info )
{
  std::string tpname = info.name();
#ifdef HAVE_BOOST
  tpname = boost::core::demangle(tpname.c_str());
#endif
  return tpname;
}



// wgl::wgl_object_name
//
std::string wgl::wgl_object_name ( const std::type_info &info,
                                   void *object )
{
  std::string tpname = wgl_type_name(info);
  std::stringstream s;
  s << "<" << tpname << " " << object << ">";
  return s.str();
}



// wgl::wgl_object_cname
//
const char *wgl::wgl_object_cname ( const std::type_info &info,
                                    void *object )
{
  std::string s = wgl_object_name(info, object);
  auto r = object_names.insert_or_assign(object, s);
  return r.first->second.c_str();
}
